package com.nwpusp.transmitter.net;

import java.util.Timer;
import java.util.TimerTask;

public class ServerList  {  
    public String address;  
    public int number;
    public String serverName;
    public Boolean isAlive = true;
	private Timer timer;
	private TimerTask task;
	private int successTick;
	private int recvNum;
      
    public ServerList(String address,String serverName, int number) {  
        this.address = address;  
        this.number = number; 
        this.serverName = serverName;
        timer = new Timer();
		task = getNewTimerTask();
		timer.schedule(task,0, 100);
    }  
    
    public void tick(){
    	 recvNum ++;
    	 successTick = recvNum;
    }
    
    public TimerTask getNewTimerTask(){
		TimerTask task = new TimerTask(){  
			public void run() { 
				successTick++;
				if(successTick-recvNum>10){
					isAlive = false;
					successTick = 0;
					recvNum = 0;
				}
				if((recvNum>=100)||(successTick>=100)){
					recvNum = 0;
					successTick = 0;
				}
			}
		}; 
		return task;
	}
}  

